/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.mallsite.modules.shop.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.mallsite.modules.shop.entity.GoodsType;
import com.mallsite.modules.shop.service.GoodsTypeService;

/**
 * 商品类型Controller
 * @author ruyang
 * @version 2020-12-04
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/goodsType")
public class GoodsTypeController extends BaseController {

	@Autowired
	private GoodsTypeService goodsTypeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public GoodsType get(String typeId, boolean isNewRecord) {
		return goodsTypeService.get(typeId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("shop:goodsType:view")
	@RequestMapping(value = {"list", ""})
	public String list(GoodsType goodsType, Model model) {
		model.addAttribute("goodsType", goodsType);
		return "modules/shop/goodsTypeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("shop:goodsType:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<GoodsType> listData(GoodsType goodsType, HttpServletRequest request, HttpServletResponse response) {
		Page<GoodsType> page = goodsTypeService.findPage(new Page<GoodsType>(request, response), goodsType); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("shop:goodsType:view")
	@RequestMapping(value = "form")
	public String form(GoodsType goodsType, Model model) {
		model.addAttribute("goodsType", goodsType);
		return "modules/shop/goodsTypeForm";
	}

	/**
	 * 保存商品类型
	 */
	@RequiresPermissions("shop:goodsType:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated GoodsType goodsType) {
		goodsTypeService.save(goodsType);
		return renderResult(Global.TRUE, text("保存商品类型成功！"));
	}
	
	/**
	 * 删除商品类型
	 */
	@RequiresPermissions("shop:goodsType:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(GoodsType goodsType) {
		goodsTypeService.delete(goodsType);
		return renderResult(Global.TRUE, text("删除商品类型成功！"));
	}
	
}